﻿#include "orderformdetails.h"
#include "ui_orderformdetails.h"
#include <QDate>
#include <QDebug>
#include <QMessageBox>
#include "mydate.h"

OrderFormDetails::OrderFormDetails(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OrderFormDetails)
{
    ui->setupUi(this);
}

OrderFormDetails::~OrderFormDetails()
{
    delete ui;
}

void OrderFormDetails::initWindowsUnit(const ReserveInfo& reserveInfo)
{
    m_hotelID = reserveInfo.getHotel();
    m_reserveID = reserveInfo.getReserve();
    ui->lb_Price->setText("¥ " + QString::number(reserveInfo.getPayment()));
    ui->pb_hotelName->setText(reserveInfo.getHotelName());
    ui->lb_location->setText(reserveInfo.getHotelLocation());
    ui->lb_houseType->setText(reserveInfo.getHouseType());
    ui->lb_phone->setText("酒店电话：" + reserveInfo.getHotelPhone());

    ui->lb_result->setText(reserveInfo.getState());
    ui->lb_Time->setText(reserveInfo.getReserveTime().split("T").join(" "));
    ui->lb_Number->setText(reserveInfo.getReserve());

    qDebug() << reserveInfo.getReserveTime();

    ui->lb_manName->setText(reserveInfo.getCheckInName());
    ui->lb_manPhoneNum->setText(reserveInfo.getCheckInTel());

    QString inTime = reserveInfo.getCheckInTime();
    QString outTime = reserveInfo.getCheckOutTime();
    QString day = GlobalVars::week[QDate::fromString(inTime,"yyyy-MM-dd").dayOfWeek()-1];
    QString timeShow = inTime + "(周" + day + ") - " + outTime + "(周";
    day = GlobalVars::week[QDate::fromString(outTime,"yyyy-MM-dd").dayOfWeek()-1];
    timeShow = timeShow + day + ")";

    int count = MyDate::DaysBetween2Date(inTime,outTime);
    timeShow += (" 共" + QString::number(count) + "晚 " +
                 QString::number(reserveInfo.getHouseCount()) + "间");
    ui->lb_liveTime->setText(timeShow);
}

void OrderFormDetails::on_pb_deleteOrder_clicked()
{
    emit signalDeleteReserveRecord(m_reserveID);
}

void OrderFormDetails::on_pb_reserveAgain_clicked()
{
    on_pb_hotelName_clicked();
}

void OrderFormDetails::on_pb_hotelName_clicked()
{
    this->close();
    emit signalHotelDetails(m_hotelID);
}

void OrderFormDetails::reserveDeleteResult(bool result, const QString& msg)
{
    if (result)
    {
        this->close();
    }
    else
    {
        QMessageBox::warning(this, "错误", msg, QMessageBox::Ok, QMessageBox::Ok);
    }
}
